//
//  CourseViewController.m
//  Yu01
//
//  Created by 蒋松涵 on 16/8/25.
//  Copyright © 2016年 蒋松涵. All rights reserved.
//

#import "CourseViewController.h"
#import "XuanModel.h"

@interface CourseViewController ()<UITableViewDataSource,UITableViewDelegate>

{
    UITableView * _tableView;
}
@property (nonatomic,strong)NSMutableArray * dataArray;

@property (nonatomic,retain) NSString *urlStr;
@property (nonatomic,retain) NSDictionary *urlParameters;


@end

@implementation CourseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"选课详情";
    
//    _urlStr = @"http://www.100xsys.com.cn/school/app/electiveCourseInfo/getInfoJson";
//    _urlParameters = [[NSDictionary alloc]initWithObjectsAndKeys:@"1",@"appWebConfigId",@"",@"electiveCourseInfo.id", nil];
//    
//    //异步执行代码
//    [self fecthDataFromNet:_urlStr parameters:_urlParameters];

    
    self.dataArray = [[NSMutableArray alloc]init];
    
    
    
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 100) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.scrollEnabled = NO;
    [self.view addSubview:_tableView];

    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(self.view.frame.size.width - 270, self.view.frame.size.height - 100, 120, 40);
    button.backgroundColor = [UIColor orangeColor];
    [button setTitle:@"报名" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(BaoMingBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [button setTintColor:[UIColor whiteColor]];
    [self.view addSubview:button];
}


#pragma mark - tableView的代理方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//    return self.dataArray.count;
    return 5;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
//    XuanModel * model = self.dataArray[indexPath.row];
    
    if (indexPath.row == 0)
    {
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 100, 30)];
//        label.text = @"色彩构成";
        label.text = self.KeChengName;
        label.font = [UIFont systemFontOfSize:20];
        label.textColor = [UIColor colorWithRed:125/255.0f green:186/255.0f blue:28/255.0f alpha:1];
        [cell addSubview:label];
        
        UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 35, 20, 25)];
        imageView.image = [UIImage imageNamed:@"其他小图标-07.png"];
        [cell.contentView addSubview:imageView];
        
        UILabel * RoomLabel = [[UILabel alloc]initWithFrame:CGRectMake(40, 35, 100, 30)];
//        RoomLabel.text = @"德育楼3-301教室";
        RoomLabel.text = [NSString stringWithFormat:@"%@ %ld-%ld",self.LouName,self.LouCeng,self.FangName];
        RoomLabel.textColor = [UIColor colorWithRed:162/255.0f green:162/255.0f blue:162/255.0f alpha:1];
        RoomLabel.font = [UIFont systemFontOfSize:12];
        [cell addSubview:RoomLabel];
        
        
        UIImageView * imageView_ = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width - 180, 35, 25, 25)];
        imageView_.image = [UIImage imageNamed:@"其他小图标-06.png"];
        [cell.contentView addSubview:imageView_];
        
        UILabel * NameLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width - 150, 35, 100, 30)];
//        NameLabel.text = @"王雷";
        NameLabel.text = self.Teacher;
        NameLabel.textColor = [UIColor colorWithRed:162/255.0f green:162/255.0f blue:162/255.0f alpha:1];
        NameLabel.font = [UIFont systemFontOfSize:12];
        [cell addSubview:NameLabel];
    }
    else if (indexPath.row == 1)
    {
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 100, 30)];
        label.text = @"课程简介";
        label.textColor = [UIColor colorWithRed:125/255.0f green:186/255.0f blue:28/255.0f alpha:1];
        [cell addSubview:label];
        
        UILabel * labels = [[UILabel alloc]initWithFrame:CGRectMake(10, 35, cell.frame.size.width, 40)];
        labels.text = self.KCJJ;
        [cell addSubview:labels];
        
    }
    else if (indexPath.row == 2)
    {
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 100, 30)];
        label.text = @"课程时间";
        label.textColor = [UIColor colorWithRed:125/255.0f green:186/255.0f blue:28/255.0f alpha:1];
        [cell addSubview:label];
        
        UILabel * label1 = [[UILabel alloc]initWithFrame:CGRectMake(20, 35, self.view.frame.size.width - 10, 30)];
//        label1.text = @"第三周，第五周，第七周，第八周  周二 17：00-16：00；周四 17：00-16：00";
        label1.text = self.kecheng;
        label1.numberOfLines = 0;
        label1.font = [UIFont systemFontOfSize:13];
        [cell addSubview:label1];
    }
    else if (indexPath.row == 3)
    {
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 100, 30)];
        label.text = @"可选班级";
        label.textColor = [UIColor colorWithRed:125/255.0f green:186/255.0f blue:28/255.0f alpha:1];
        [cell addSubview:label];
        
        UILabel * label1 = [[UILabel alloc]initWithFrame:CGRectMake(20, 35, self.view.frame.size.width - 10, 30)];
//        label1.text = @"广告1班，动漫1班，园林设计";
        label1.text = self.RoomName;
        label1.numberOfLines = 0;
        label1.font = [UIFont systemFontOfSize:13];
        [cell addSubview:label1];
    }
    else
    {
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 100, 30)];
        label.text = @"学分设置";
        label.textColor = [UIColor colorWithRed:125/255.0f green:186/255.0f blue:28/255.0f alpha:1];
        [cell addSubview:label];
        
        UILabel * label1 = [[UILabel alloc]initWithFrame:CGRectMake(20, 35, self.view.frame.size.width - 10, 30)];
//        label1.text = @"一节课0.5个学分，总共4个学分";
        label1.text = [NSString stringWithFormat:@"%ld 学分",self.XueFen];
        label1.numberOfLines = 0;
        label1.font = [UIFont systemFontOfSize:13];
        [cell addSubview:label1];
    }
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        return 80;
    }
    else if (indexPath.row == 1)
    {
        return 90;
    }
    else if (indexPath.row == 2)
    {
        return 90;
    }
    else if (indexPath.row == 3)
    {
        return 90;
    }
    else
    {
        return 90;
    }

}


#pragma mark - Button点击方法
-(void)BaoMingBtnClick
{
    NSLog(@"报名点击了");
    
    
    _urlStr = @"http://www.100xsys.com.cn/school/app/ajax_electiveCourseStudentInfo/add";
    _urlParameters = [[NSDictionary alloc]initWithObjectsAndKeys:@"1",@"appWebConfigId",@"id",@"electiveCourseStudentInfo. electiveCourseInfoId",@"",@"electiveCourseStudentInfo. studentInfoId", nil];
    
    //异步执行代码
    [self fecthDataFromNet:_urlStr parameters:_urlParameters];

    
    
}
#pragma mark - 数据请求
//请求数据
- (void)fecthDataFromNet:(NSString *)url parameters:(NSDictionary *)parameter {
    
    NSLog(@"%@",url);
    NSLog(@"%@",parameter);
    //初始化请求工具
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:url parameters:parameter progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
        
        NSLog(@"**********%@",dic[@"success"]);
//        NSMutableArray * List = dic[@"info"];
//        
//        for (NSDictionary * dicList in List)
//        {
//            XuanModel * model = [[XuanModel alloc]init];
//            [model setValuesForKeysWithDictionary:dicList];
//            [self.dataArray addObject:model];
//            NSLog(@"----%ld",self.dataArray.count);
//        }
//        [_tableView reloadData];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        
    }];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
